package com.tensai.study.新概念.函数式编程.completableFuture;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @author Tensai
 */
public class WhenComplete {

    public static void main(String[] args) {
        whenComplete();
    }

    private static void whenComplete() {
        String[] list = {"a", "b", "c", null};
        List<CompletableFuture<String>> resList = new ArrayList<>();
        for (String str : list) {
            resList.add(CompletableFuture.supplyAsync(() -> str).thenApply(String::toUpperCase));
        }

        CompletableFuture.allOf(resList.toArray(new CompletableFuture[0]))
                .whenComplete((r, e) -> {
                    if (null != e) {
                        throw new RuntimeException(e);
                    }
                });
    }
}
